import 'package:common_utils/common_utils.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nft_shop/market/model/models.dart';
import 'package:nft_shop/net/dio_api.dart';
import 'package:nft_shop/net/service_repository.dart';
import 'package:nft_shop/res/constant.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/util/other_utils.dart';

import '../model/models.dart';

class BoxDetailsConteroller extends GetxController {
  static final boxDetailsInfo = "BoxDetailsInfo";

  late BoxInfoModel _boxInfo;
  String _countDownTime = "";

  ///状态
  late int status = LoadStatusType.loading;

  ///创作者介绍
  double heght1 = 175;

  ///作品描述
  double heght2 = 175;

  ///细节展示
  double heght3 = 175;

  //作品故事
  double heght4 = 175;

  ///当前高度
  double currentHeight = 110;

  //1单个藏品详情 2整体铸造详情  3整体详情
  int type = 0;

  BoxInfoModel get boxInfo => _boxInfo;
  String get countDownTime => _countDownTime;

  set setCountDownTime(value) {
    _countDownTime = value;
    update(['countDownTime']);
  }

  //是否存在
  bool get hasBoxInfo => ObjectUtil.isNotEmpty(_boxInfo);

  static BoxDetailsConteroller get to => Get.put(BoxDetailsConteroller());

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
  }

  //获取数据
  void getDataList(String id) async {
    try {
      print("盲盒ID是--${id}");
      //1单个盲盒详情 2整体铸造详情  3整体详情
      if (type == 1) {
        _boxInfo = await ServiceRepository.goodsInfoMang(id: id);
      } else if (type == 2) {
        _boxInfo = await ServiceRepository.mangInfo(id: id);
      } else if (type == 3) {
        _boxInfo = await ServiceRepository.mangInfo(id: id);
      }
      await getPageHeight();
      status = LoadStatusType.success;
    } catch (e, s) {
      status = LoadStatusType.empty;
      http.setError(e, s);
    }
    update();
  }

  //计算高度
  Future<void> getPageHeight() async {
    Rect rect2 = await ImageUtil().getImageWH(
      url: boxInfo.info!.detail ?? "",
    );

    print("图片高度-----${rect2.height}--${rect2.width}");

    heght1 = Global.boundingTextSize(
                _boxInfo.info!.introduce ?? "",
                TextStyle(
                    fontSize: 12,
                    color: Global.kTheme.inputHint1,
                    fontFamily: Global.mySemiboldFont),
                maxWidth: ScreenUtil.getScreenW(Get.context!) - 30)
            .height +
        110;

    heght2 = _boxInfo.specialBlindBoxList!.length * 70 + 90;

    heght3 = ScreenUtil().getHeightPx(rect2.height) + 90;

    heght4 = Global.boundingTextSize(
                _boxInfo.info!.story ?? "",
                TextStyle(
                    fontSize: 12,
                    color: Global.kTheme.inputHint1,
                    fontFamily: Global.mySemiboldFont),
                maxWidth: ScreenUtil.getScreenW(Get.context!) - 30)
            .height +
        70;

    currentHeight = heght1;
  }

  ///改变高度
  void changeHeight(int index) {
    if (index == 0) {
      currentHeight = heght1;
    } else if (index == 1) {
      currentHeight = heght2;
    } else if (index == 2) {
      currentHeight = heght3;
    } else if (index == 3) {
      currentHeight = heght4;
    }
    print("高度---${currentHeight}--");
    update([boxDetailsInfo]);
  }
}
